package src.serverSide;

import java.util.HashMap;

public class AccessLog {
	private HashMap<String, Integer> active = new HashMap<String, Integer>();
	private PassLog passlog;
	
	public AccessLog(PassLog in) {
		passlog = in;
	}
	
	/**
	 * This method adds the desired user, or logs him in
	 * @param address The address to associate the user with
	 * @param userid The userid of the desired user
	 */
	public void setUser(String address, int userid) {
		active.put(address, userid);
	}
	
	/**
	 * This method removes a certian user from the list
	 * @param address The address of the user to remove
	 */
	public void removeUser(String address) {
		active.remove(address);
	}
	
	/**
	 * This method retrieves the user associated with an access address
	 * It first checks if the user is still logged in
	 * @param address The address of the user to search for
	 * @return The user ID, or zero if none is found
	 */
	public int getUserID(String address) {
		int userid = active.get(address);
		if (passlog.checkActivity(userid)) return userid;
		else active.remove(address);
		return 0;
	}
	
}
